<%@ include file="/common/taglibs.jsp" %>
<c:set var="listOrdersUrl"><spring:url value="/orders/listOrders.html"/></c:set>
<c:set var="calendarImgUrl"><spring:url value="/images/calendar.gif"/></c:set>

<head>
	<title><spring:message code="orders.listOrders.header"/></title>
	<script type="text/javascript" src="<spring:url value='/scripts/development-bundle/jquery.jstepper-1.2.js'/>"></script>
	<script type="text/javascript">
	$(document).ready(function() {
		$("input[id$=Time]").datepicker({
			changeYear: true, 
			yearRange : 'c-20:c+20', 
			showOn: "button", 
			buttonImage: "${calendarImgUrl}", 
			buttonImageOnly: true
		});
		$("input[id$=Price]").jStepper();
	});
	</script>
</head>
<p>
	<spring:message code="orders.listOrders.header"/>
</p>
<table>
	<tr>
		<td>
		<form action="${listOrdersUrl}" method="get">
		<table>
			<tr>
				<td><label for="userAccountName"><spring:message code="orders.listOrders.userAccountName"/></label></td>
				<td><input type="text" name="userAccountName" id="userAccountName" value="${param.userAccountName}"/></td>
				
				<td><label for="recipientName"><spring:message code="orders.listOrders.recipientName"/></label></td>
				<td><input type="text" name="recipientName" id="recipientName" value="${param.recipientName}"/></td>
				
				<td><label for="orderStatus"><spring:message code="orders.listOrders.orderStatus"/></label></td>
				<td><select name="orderStatus" id="orderStatus">
					<option></option>
					<c:forEach var="orderStatus" items="${orderStatuses}">
						<option value="${orderStatus}" <c:if test='${param.orderStatus == orderStatus}'>
								<c:out value="selected='selected'"></c:out>
							</c:if>><spring:message code="${sf:getOrderStatusMessageCode(orderStatus)}"/></option>
					</c:forEach>
				</select>
			</tr>
			<tr>
				<td><label for="fromUpdateTime"><spring:message code="orders.listOrders.fromUpdateTime"/></label></td>
				<td><input type="text" name="fromUpdateTime" id="fromUpdateTime" value="${param.fromUpdateTime}" readonly="readonly"/></td>
				
				<td><label for="toUpdateTime"><spring:message code="orders.listOrders.toUpdateTime"/></label></td>
				<td><input type="text" name="toUpdateTime" id="toUpdateTime" value="${param.toUpdateTime}" readonly="readonly"/></td>
				
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td><label for="fromCreateTime"><spring:message code="orders.listOrders.fromCreateTime"/></label></td>
				<td><input type="text" name="fromCreateTime" id="fromCreateTime" value="${param.fromCreateTime}" readonly="readonly"/></td>
				
				<td><label for="toCreateTime"><spring:message code="orders.listOrders.toCreateTime"/></label></td>
				<td><input type="text" name="toCreateTime" id="toCreateTime" value="${param.toCreateTime}" readonly="readonly"/></td>
				
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td><label for="fromPrice"><spring:message code="orders.listOrders.fromPrice"/></label></td>
				<td><input type="text" name="fromPrice" id="fromPrice" value="${param.fromPrice}"/></td>
				
				<td><label for="toPrice"><spring:message code="orders.listOrders.toPrice"/></label></td>
				<td><input type="text" name="toPrice" id="toPrice" value="${param.toPrice}"/></td>
				
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td colspan="6" style="text-align: right;">
					<button type="submit" class="aButton" style="margin-right: 10px;"><spring:message code="orders.listOrders.submit"/></button>
					<button type="reset" class="aButton" style="margin-right: 10px;"><spring:message code="orders.listOrders.reset"/></button>
				</td>
			</tr>
		</table>
		</form>
		</td>
	</tr>
	<tr>
		<td>
		<display:table name="orders" cellspacing="0" cellpadding="0" requestURI="" 
		   	defaultsort="1" id="order" pagesize="25" class="table" export="true">
		   	
		    <display:column sortable="true" titleKey="orders.listOrders.order.id" >
		    	<a href="<spring:url value='/orders/maintainOrder.html'>
		    		<spring:param name="orderId" value="${order.id}" />
		    		<spring:param name="previousPath" value="${currentPath}" />
		    		</spring:url>">${order.id}</a>
		    </display:column>
		    	
		    <display:column sortable="true" titleKey="orders.listOrders.order.recipientName" 
		    	property="recipientName"/>
		    
		    <display:column sortable="true" titleKey="orders.listOrders.order.orderStatus">
		    	<spring:message code="${sf:getOrderStatusMessageCode(order.status)}"/>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="orders.listOrders.order.payment">
		    	<spring:message code="${sf:getPaymentMessageCode(order.payment)}"/>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="orders.listOrders.order.payment.paid">
		    	<c:choose>
		    		<c:when test="${order.payment.paid}">
		    			<spring:message code="orders.listOrders.order.payment.paid.yes"/>
		    		</c:when>
		    		<c:otherwise>
		    			<spring:message code="orders.listOrders.order.payment.paid.no"/>
		    		</c:otherwise>
		    	</c:choose>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="orders.listOrders.order.createTime">
		    	<fmt:formatDate value="${order.createTime}" pattern="${datePattern}"/>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="orders.listOrders.order.updateTime">
		    	<fmt:formatDate value="${order.updateTime}" pattern="${datePattern}"/>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="orders.listOrders.order.price">
		    	<c:out value="$${order.price}"/>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="orders.listOrders.order.pickingList">
		    	<c:set var="numberOfPickingLists" value="${fn:length(order.pickingLists)}"></c:set>
		    	<c:choose>
		    		<c:when test="${numberOfPickingLists > 0}">
		    			<a href="<spring:url value="/pickingLists/listPickingLists.html">
		    				<spring:param name="orderId" value="${order.id}"/>
		    				<spring:param name="previousPath" value="${currentPath}"/>
		    			</spring:url>">${numberOfPickingLists}</a>
		    		</c:when>
		    		<c:otherwise>0</c:otherwise>
		    	</c:choose>
		    </display:column>
		    
		    <display:setProperty name="paging.banner.item_name">
		    	<spring:message code="orders.listOrders.item"/>
		    </display:setProperty>
		    <display:setProperty name="paging.banner.items_name">
		    	<spring:message code="orders.listOrders.items"/>
		    </display:setProperty>
		
		    <display:setProperty name="export.excel.filename" value="Orders.xls"/>
		    <display:setProperty name="export.csv.filename" value="Orders.csv"/>
		    <display:setProperty name="export.pdf.filename" value="Orders.pdf"/>
		</display:table>
		</td>
	</tr>
</table>